<%@ page import="fdq.pojo.Message" %><%--
  Created by IntelliJ IDEA.
  User: 82606
  Date: 2023/11/8
  Time: 23:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <style>
        table,tr,td{
            border: black 2px solid;
        }
        #show{
            float: left;
            margin-right: 200px;
        }
    </style>
</head>
<body>
<h1 style="text-align: center">留言板</h1>
<%--创建全部留言对象--%>
<%! Message[] messages;%>
<% messages = (Message[]) request.getAttribute("allMessages"); %>

<table id="show">
    <tr>
        <th>留言人</th>
        <th>留言内容</th>
        <th>留言时间</th>
        <th>删除按钮</th>
    </tr>
<% for(Message m : messages){ %>
    <tr>
        <td><%= m.getMname()%></td>
        <td><%= m.getMessage()%></td>
        <td><%= m.getTime()%></td>
        <td><button class="deleteButton" name=<%= m.getMid()%>>删除</button> </td>
    </tr>
<%} %>

</table>

<form action="/insert">
<table id="add">
    <tr><th>添加留言</th></tr>
    <tr>
        <td><label>姓名：</label></td>
        <td><input name="mname" type="text"></td>
    </tr>
    <tr>
        <td><label>留言内容：</label></td>
        <td><input name="message" type="text"></td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" value="添加"></td>
        <td><input type="reset" value="重置"></td>
    </tr>
</table>
</form>

</body>
</html>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    // var button = $("#deleteButton").attr("name");
    // console.log(button);
    $('.deleteButton').click(function (){
        var mid = $(this).attr("name");
        console.log(mid);
        $.ajax({
            url:"http://localhost:8080/delete?mid="+mid ,
            type:"POST",

        })
    });
</script>
